home *** CD-ROM | disk | FTP | other *** search
- #define __DebugVersion 1
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** RAMInit.c: An INIT which installs DRVR for RamDisk
- **
- ** by Gordon Sheridan and Jim Luther
- ** modified incessantly by Brian Bechtel
- **
- ** File: RamINIT.c
- **
- ** Copyright © 1992-1995 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DTS Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes.
- **
- ** Change History (most recent first):
- **
- ** Change History (most recent first):
- **
- ** <1.2> 07/03/95 BL°B Many changes for Universal Header 2.0
- ** compliance. Changed how we install driver.
- ** Other bug fixes. See "Changes in 1.2" for
- ** details.
- ** <7> 06/10/94 BL°B Explicitly set zone to system zone before
- ** getting the DRVR resource. Symantec 7.0
- ** doesn't set the System attribute on the DRVR
- ** resource. This can be hard to track down.
- ** <6> 05/19/94 BL°B Modified debugger macros to avoid use of ANSI
- ** routines, and weird c-string dependencies.
- ** <5> 10/15/93 JML Added code to resize unit table if needed.
- ** <4> 10/14/93 JML Implement AddDebuggerLabels routine for MacsBug.
- ** Added Panic debug macros.
- ** <3> 6/29/93 gs Change AddDriveToQueue to start with drive number 5.
- ** <2> 6/28/93 gs Change _DebugVersion to __DebugVersion
- ** <1> 6/13/93 gs Implement AddDebuggerLabels routine for TMON.
- ** <0> 4/17/92 gs Clean up for Sample Code release.
- **/
-
- #include "RamDisk.h"
-
- #ifdef __DebugVersion
- #include <string.h>
- #include <TextUtils.h>
- #endif
-
- /*****************************************************************************/
-
- /*
- ** Prototypes
- */
-
- pascal void ShowIcon7(short iconId, Boolean advance);
- pascal short AddMyDrive (long size,short driveRef); /* returns drive number */
- pascal OSErr DRVRInstall (Handle,short);
- pascal OSErr DRVRRemove (short);
- pascal OSErr InstallGlue (Handle,short);
-
- void main (void);
- OSErr InitializeGlobals (DrvrGlobals *driverGlobals);
- Ptr GetUnitTableBase (void);
- void SetUnitTableBase (Ptr newUnitTableBase);
- short GetUnitEntryCount (void);
- void SetUnitEntryCount (short newUnitEntryCount);
- OSErr GrowUnitTable (void);
- short GetUnusedDrvrRefNum (void);
- OSErr GetDrvrRefNum (short *drvrRefNum);
- OSErr MyDriverInstall (Ptr drvrPtr, short drvrRefNum);
- void MyDriverRemove (short drvrRefNum);
- OSErr AddDriveToQueue (long size, short drvrRef, short *driveNum);
- OSErr RemoveDrive (short driveNum, DrvQElPtr *drivePtr);
-
- #ifdef __DebugVersion
- short NumToolboxTraps (void);
- TrapType GetTrapType (short theTrap);
- Boolean TrapAvailable (short theTrap);
- void AddDebuggerLabels (DrvrGlobals driverGlobals);
- #endif __DebugVersion
-
- /*****************************************************************************/
-
- /*
- ** main
- */
-
- void main (void)
- {
- DrvrGlobals driverGlobals;
- short csParam[11];
- short drvrRefNum = 0;
- short driveNum = 0;
- DrvQElPtr driveQElPtr;
- OSErr result;
- AuxDCEPtr dcePtr;
- Handle driverHandle = nil;
- char handleState;
-
- #ifdef THINK_C
- RememberA0();
- SetUpA4();
- #endif
- #ifdef __MWERKS__
- long oldA4=SetCurrentA4();
- #endif
-
-
- Panic("\pStarting RAMDisk");
- ShowIcon7(rLoadOKIcon,false); /* show OK icon to indicate we're executing */
-
- result = InitializeGlobals(&driverGlobals);
- if (result != noErr)
- {
- Panic("\pCould not initialize globals");
- goto Done;
- }
-
- driverGlobals.ramDisk = NewPtrSysClear(driverGlobals.ramSize);
- if (driverGlobals.ramDisk == nil)
- {
- Panic("\pNewSysPtr = nil");
- result = memFullErr;
- goto Done;
- }
-
- #ifdef __DebugVersion
- AddDebuggerLabels(driverGlobals);
- #endif __DebugVersion
-
- result = GetDrvrRefNum(&drvrRefNum);
- if (result != noErr)
- {
- Panic("\pGetDrvrRefNum failed!");
- goto Done;
- }
-
- SetZone(SystemZone()); /* <7> */
-
- driverHandle = Get1NamedResource(kDRVRType, kDriverName);
- result = ResError();
- if (result != noErr)
- {
- Panic("\pGet1NamedResource failed!");
- goto Done;
- }
-
- HLock(driverHandle);
- DetachResource(driverHandle);
- result = ResError();
- if (result != noErr)
- {
- Panic("\pDetachResource failed!");
- goto Done;
- }
-
- SetZone(ApplicZone()); /* <7> */
-
- result = MyDriverInstall(*driverHandle, drvrRefNum);
- if (result != noErr)
- {
- Panic("\pMyDriverInstall failed!");
- goto Done;
- }
-
- result = OpenDriver(kDriverName, &drvrRefNum);
- if (result != noErr)
- {
- Panic("\pOpenDriver failed");
- goto Done;
- }
-
- /* put in drive queue */
- result = AddDriveToQueue (driverGlobals.ramSize / 512, drvrRefNum, &driveNum);
- if (result != noErr)
- {
- Panic("\pAddMyDrive returned negative driveNum!");
- goto Done;
- }
- /* driveNum now = drive number */
-
- /* Save driveNum in our globals so driver code can verify drive number in
- Prime, Status and Control calls (if need be). The driver also checks
- driveNum in the driver globals for a non-zero value before accepting
- regular prime, control and status calls. */
- driverGlobals.driveNumber = driveNum;
-
- /* set drivers globals */
- *(Ptr *)csParam = (Ptr)&driverGlobals;
- result = Control(drvrRefNum, setGlobalsCC, (Ptr)csParam);
- if (result != noErr)
- {
- Panic("\pControl returned err");
- goto Done;
- }
-
- /* check to see if it got them */
- result = Status(drvrRefNum, getGlobalsSC, (Ptr)csParam);
- if ((result != noErr) || (driverGlobals.ramSize != *(long *)csParam))
- {
- Panic("\pStatus returned err");
- goto Done;
- }
-
- /* zero & mount */
- result = DIZero(driveNum, driverGlobals.volumeName);
- if (result != noErr)
- {
- Panic("\pDIZero returned err");
- goto Done;
- }
-
- Done:
- if (result == noErr)
- ShowIcon7(rLoadOKIcon,true); /* draw OK icon and move pen */
- else
- {
- dcePtr = (AuxDCEPtr)GetDCtlEntry(drvrRefNum);
- if (dcePtr != nil)
- if ((*dcePtr).dCtlFlags & dOpened)
- {
- /* Driver is open - close it */
- result = CloseDriver(drvrRefNum);
- if (result == noErr)
- /* If driver was closed, ramDisk memory was released! */
- driverGlobals.ramDisk = nil;
- }
-
- if (driveNum != 0)
- {
- result = RemoveDrive(driveNum, &driveQElPtr); /* ignore errors */
- if (result == noErr)
- /* Dispose of the DrvQEl. Since it was allocated as a
- MyDrvQEl record, we have to subract 4 from the address */
- DisposePtr((Ptr)((Ptr)(driveQElPtr) - 4));
- }
-
- if (drvrRefNum != 0)
- MyDriverRemove (drvrRefNum);
-
- if (driverHandle != nil)
- {
- handleState = HGetState(driverHandle);
- if (handleState & 0x20) /* Is driverHandle a resource? */
- ReleaseResource(driverHandle); /* yes, release it */
- else
- DisposeHandle(driverHandle); /* no, dispose it */
- }
-
- if (driverGlobals.ramDisk != nil)
- DisposePtr(driverGlobals.ramDisk);
-
- #ifdef __DebugVersion
- /* ••• Need to add routine to remove TMON/MacsBug debugging macros */
- #endif __DebugVersion
-
- ShowIcon7(rLoadBadIcon,true); /* draw bad load icon and move pen */
- }
- #ifdef THINK_C
- RestoreA4();
- #endif
- #ifdef __MWERKS__
- SetA4(oldA4);
- #endif
- }
-
- /*****************************************************************************/
-
- /*
- ** InitializeGlobals
- **
- ** Initialize the globals using data read from resources.
- */
-
- OSErr InitializeGlobals (DrvrGlobals *driverGlobals)
- {
- OSErr result = -1;
- Handle physicalIconHandle, mediaIconHandle;
- ConfigRecHandle configHandle;
- long length;
-
- driverGlobals->ramDisk = nil; /* RAM disk memory isn't allocated yet */
-
- /* Get the user configuration, icons, and the "where" string */
- configHandle = (ConfigRecHandle)Get1Resource ('RDcf', 0);
- physicalIconHandle = Get1Resource('ICN#', rPhysicalIcon);
- mediaIconHandle = Get1Resource('ICN#', rMediaIcon);
-
- if (configHandle && physicalIconHandle && mediaIconHandle)
- {
- /* See if we are supposed to install */
- if ((**configHandle).install)
- {
- /* Copy the user's preferred volume name to the driver globals. */
- length = (**configHandle).volumeName[0]+1;
- BlockMove((**configHandle).volumeName, driverGlobals->volumeName, length);
-
- /* Copy ICN# to driver globals so it has a physical location icon for volumes. */
- BlockMove( &(**physicalIconHandle), (Ptr)(driverGlobals->physicalIcon), kLargeIconSize);
-
- /* Copy ICN# to driver globals so it has a default media icon for volumes. */
- BlockMove( &(**mediaIconHandle), (Ptr)(driverGlobals->mediaIcon), kLargeIconSize);
-
- /* Put the drive location string into the driver globals. */
- GetIndString(driverGlobals->locationStr, rStringList, rLocationStr);
- if (ResError() != noErr)
- BlockMove("\pIn RAM", driverGlobals->locationStr, 7);
-
- driverGlobals->ramSize = (**configHandle).size * 1024;
-
- result = noErr;
- }
- }
-
- if (configHandle)
- ReleaseResource((Handle)configHandle);
- if (physicalIconHandle)
- ReleaseResource(physicalIconHandle);
- if (mediaIconHandle)
- ReleaseResource(mediaIconHandle);
-
- return (result);
- }
-
- /*****************************************************************************/
-
- /*
- ** GetUnitTableBase
- ** SetUnitTableBase
- ** GetUnitEntryCount
- ** SetUnitEntryCount
- **
- ** Functions to encapsulate access to the low-memory globals UTableBase and
- ** UnitNtryCnt.
- */
-
- Ptr GetUnitTableBase (void)
- {
- return (LMGetUTableBase());
- }
-
- void SetUnitTableBase (Ptr newUnitTableBase)
- {
- LMSetUTableBase(newUnitTableBase);
- }
-
- //GetUnitEntryCount
- //1.2 Brian Bechtel
- // Changed to use new definition in Universal Headers
- short GetUnitEntryCount (void)
- {
- return (LMGetUnitTableEntryCount());
- }
-
- //SetUnitEntryCount
- //1.2 Brian Bechtel
- // Changed to use new definition in Universal Headers
- void SetUnitEntryCount (short newUnitEntryCount)
- {
- LMSetUnitTableEntryCount(newUnitEntryCount);
- }
-
- /*****************************************************************************/
-
- /*
- ** GrowUnitTable
- **
- ** Allocates and switches to a larger unit table. If the current unit table
- ** has less than kMinUnitNum entries, the unit table is increased to
- ** kMinUnitNum + 16. If the current unit table has more than kMinUnitNum
- ** entries, the unit table is increased by 4 entries up to kMaxUTEntries.
- */
-
- OSErr GrowUnitTable (void)
- {
- OSErr result = noErr;
- Ptr oldUnitTableBase;
- short oldUnitEntryCount;
- Ptr newUnitTableBase;
- short newUnitEntryCount;
-
- oldUnitTableBase = GetUnitTableBase();
- oldUnitEntryCount = GetUnitEntryCount();
-
- if (oldUnitEntryCount < kMinUnitNum)
- newUnitEntryCount = 64;
- else
- newUnitEntryCount = oldUnitEntryCount + 4;
-
- if (newUnitEntryCount <= kMaxUTEntries) /* The unit table cannot grow past kMaxUTEntries (128) */
- {
- /* Allocate the new unit table */
- newUnitTableBase = NewPtrSysClear(newUnitEntryCount * sizeof(long)); // mike wiese
- if (newUnitTableBase != nil)
- {
- /* Copy the old unit table into the new. Although the
- ** "Driver Education" Tech Note says that you need to disable
- ** interrupts around this operations, you don't. You only need to
- ** perform the steps in the right order because anything that uses
- ** the unit table at interrupt time shouldn't be saving the UTableBase
- ** or UnitNtryCnt values between calls (if they do, they'll break even
- ** if we do disable interrupts around these steps).
- */
-
- /* First, copy the current unit table into the new unit table */
- BlockMove(oldUnitTableBase, newUnitTableBase, oldUnitEntryCount * 4);
-
- /* Now, switch to the new unit table. After this step, the */
- /* Device Manager will be using the new unit table. */
- SetUnitTableBase(newUnitTableBase);
-
- /* Now, tell the system the table is larger. */
- SetUnitEntryCount(newUnitEntryCount);
-
- /* Everything is switched, so we can get rid of the old unit table */
- DisposPtr(oldUnitTableBase);
- }
- else
- {
- Panic("\pGrowUnitTable: New unit table could not be allocated");
- result = unitTblFullErr;
- }
-
- }
- else
- {
- Panic("\pGrowUnitTable: Unit table cannot grow past kMaxUTEntries (128)");
- result = unitTblFullErr;
- }
-
- return (result);
- }
-
- /*****************************************************************************/
-
- /*
- ** GetUnusedDrvrRefNum
- **
- ** Finds the first unused unit table entry >= kMinUnitNum. Returns 0 if no
- ** unused entry is found.
- */
-
- //1.2 Matthew E. Axsom
- // The problem occurs in the following lines of code:
- //
- // > while ((unitTable[unitNumber] != nil) && (unitNumber < unitEntryCount))
- // > ++unitNumber;
- // >
- // > if (unitTable[unitNumber] == nil) /* Find an empty entry? */
- // > /* Yes, then calculate its driver reference number */
- // > drvrRefNum = -1 * (unitNumber +1);
- //
- // The above code works just fine as long as the unit table has at least 1 empty
- // slot in it. If the unit table is completely full, i.e., no empty slots then
- // this section of code can produce an invalid drvrRefNum. I believe that if the
- // table is full that the routine should return 0 (zero) and then grow the unit
- // table and try again. Instead, here's what can happen if the unit table is
- // completely full:
- //
- // If there are no empty slots in the unit table then eventually unitNumber will
- // be >= unitEntryCount and the 'while' loop will terminate with unitNumber equal to
- // unitEntryCount. Since there are only unitEntryCount-1 entries in the unit table,
- // unitNumber now contains an "out of bounds" index for the unit table. After
- // falling out of the 'while' loop, the 'if' statement then uses the "out of bounds"
- // unitNumber for indexing into unitTable. At this point if the address pointed
- // to by unitTable[unitNumber] is nil then we get a "valid" drvrRefNum which is
- // really invalid because unitNumber is "out of bounds". What should happen is
- // that the table is full and a drvrRefNum of 0 (zero) be returned so the unit
- // table can be grown.
- //
- // Since I needed to load a driver, I corrected the code this way:
- //
- // > while (unitNumber < unitEntryCount) {
- // > if (unitTable[unitNumber] == nil) { /* Find an empty entry? */
- // > /* Yes, then calculate its driver reference number */
- // > drvrRefNum = -1 * (unitNumber +1);
- // > break;
- // > }
- // > else
- // > ++unitNumber;
- // > }
- //
- // I tested this out and, as far as I can tell, it works. It correctly detects a
- // full unit table and returns 0. The calling routine then grows the unit table
- // and tries again, this time with success.
- //
-
- short GetUnusedDrvrRefNum (void)
- {
- AuxDCEPtr *unitTable;
- short unitEntryCount;
- short unitNumber;
- short drvrRefNum = 0; /* default to no entry found */
-
- unitTable = (AuxDCEPtr *)GetUnitTableBase();
- unitEntryCount = GetUnitEntryCount();
-
- /* Look for the first empty entry */
- unitNumber = kMinUnitNum;
- while (unitNumber < unitEntryCount) {
- if (unitTable[unitNumber] == nil) { /* Find an empty entry? */
- /* Yes, then calculate its driver reference number */
- drvrRefNum = -1 * (unitNumber +1);
- break;
- }
- else
- ++unitNumber;
- }
-
- return (drvrRefNum);
- }
-
- /*****************************************************************************/
-
- /*
- ** GetDrvrRefNum
- **
- ** Gets a reference number for our driver to use. Grows the unit table if
- ** if is less than kMinUnitNum or if there are no empty entries in the
- ** unit table.
- */
-
- OSErr GetDrvrRefNum (short *drvrRefNum)
- {
- OSErr result = noErr;
-
- *drvrRefNum = 0;
-
- /* See if we need to resize before we even look for an empty entry */
- if (GetUnitEntryCount() < kMinUnitNum)
- /* yep, so do it */
- result = GrowUnitTable();
-
- if (result == noErr)
- {
- /* Find an unused driver reference number */
- *drvrRefNum = GetUnusedDrvrRefNum();
- if (*drvrRefNum == 0)
- {
- /* Didn't find one, so try growing the unit table one more time */
- result = GrowUnitTable();
-
- if (result == noErr)
- /* Find an unused driver reference number */
- *drvrRefNum = GetUnusedDrvrRefNum();
- }
- if (*drvrRefNum == 0)
- result = unitTblFullErr;
- }
-
- return (result);
- }
-
- /*****************************************************************************/
-
- /*
- ** MyDriverInstall
- **
- ** Allocate a device control entry low in memory, initialize its dCtlDriver,
- ** dCtlFlags, and dCtlRefNum fields, and then add it to the unit table.
- */
- //1.2 John Wang
- // Instead of creating a AuxDCE record, we were creating a DCtlEntry.
- // Because the record is smaller, the dCtlSlot field is garbage and
- // causes _SUpdateSrt to be called when the driver is closed.
- OSErr MyDriverInstall (Ptr drvrPtr, short drvrRefNum)
- {
- OSErr result = noErr;
- short unitNum;
- AuxDCEHandle *unitTable;
- AuxDCEHandle dceHandle;
-
- unitNum = -1 * (drvrRefNum + 1);
-
- unitTable = (AuxDCEHandle *)GetUnitTableBase();
-
- /* Make room as low as possible because the device control entry will */
- /* be locked while the driver is open */
- ResrvMem(sizeof(AuxDCE));
-
- dceHandle = (AuxDCEHandle)NewHandleSysClear(sizeof(AuxDCE));
- if (dceHandle != nil)
- {
- HLock((Handle)dceHandle); //<1.2>
- (**dceHandle).dCtlDriver = drvrPtr;
- (**dceHandle).dCtlFlags &= ~dRAMBased; /* dRAMBased = dCtlDriver is handle */
- (**dceHandle).dCtlRefNum = drvrRefNum;
-
- /* Put dceHandle in the unit table */
- unitTable[unitNum] = dceHandle;
- }
- else
- {
- result = memFullErr;
- }
-
- return (result);
- }
-
- /*****************************************************************************/
-
- /*
- ** MyDriverRemove
- **
- ** Used to remove a driver. The unit table entry is cleared, the driver
- ** handle is disposed, and the device control entry is disposed.
- */
-
- void MyDriverRemove (short drvrRefNum)
- {
- short unitNum;
- AuxDCEHandle *unitTable;
- AuxDCEHandle dceHandle;
-
- unitNum = -1 * (drvrRefNum + 1);
- unitTable = (AuxDCEHandle *)GetUnitTableBase();
-
- if (unitNum > 0 && (unitNum <= kMaxUTEntries))
- {
- dceHandle = unitTable[unitNum];
- if (dceHandle != nil)
- {
- /* Make sure the driver isn't open! */
- if (((**dceHandle).dCtlFlags & dOpened) == 0)
- {
- unitTable[unitNum] = nil;
- //1.2 Mike Wiese:
- // DriverRemove should not be disposing the driverhandle stored in dCltDriver,
- // since the install routine calls ReleaseResource or DisposHandle as appropriate.
- // Plus, if it's pointer based as it should be, disposeHandle won't work.
- // if ((**dceHandle).dCtlDriver != nil)
- // DisposHandle((Handle)(**dceHandle).dCtlDriver);
-
- HUnlock((Handle)dceHandle); //<1.2>
- DisposHandle((Handle)dceHandle);
- }
- }
- }
- }
-
- /*****************************************************************************/
-
- /*
- ** AddDriveToQueue
- **
- ** Find the first unused drive number greater than 4, allocate and initialize
- ** a drive queue element (including the drive flags), and add the drive queue
- ** element to the drive queue.
- */
-
- OSErr AddDriveToQueue (long size, short drvrRef, short *driveNum)
- {
- OSErr result = noErr;
- QHdrPtr driveQHdr;
- DrvQEl *drivePtr;
- MyDrvQElPtr newDrivePtr;
- Boolean driveNumFound = false;
-
-
- driveQHdr = GetDrvQHdr();
-
- /* find first free drive number */
- *driveNum = 5; /* drive numbers 1-4 are reserved */
- while (! driveNumFound)
- {
- drivePtr = (DrvQEl *)driveQHdr->qHead; /* get first drive */
- while (drivePtr && *driveNum != drivePtr->dQDrive) /* order of tests important! */
- drivePtr = (DrvQEl *)drivePtr->qLink; /* get next drive */
-
- if (drivePtr == nil)
- driveNumFound = true;
- else
- ++(*driveNum);
- }
-
- if (*driveNum > 0) /* must be a positive short */
- {
- /* allocate new drive queue element */
- newDrivePtr = (MyDrvQElPtr)NewPtrSysClear(sizeof(MyDrvQEl));
- if (newDrivePtr != nil)
- {
- newDrivePtr->flags = 0x00080000; /* non-ejectable, disk not locked */
- newDrivePtr->qType = 1; /* see IM vol.4 p.181 */
- newDrivePtr->dQDrive = *driveNum; /* •• dQDrive and dQRefNum are filled */
- newDrivePtr->dQRefNum = drvrRef; /* •• in by AddDrive */
- newDrivePtr->dQFSID = 0; /* HFS */
- newDrivePtr->dQDrvSz = size & 0x0000FFFF; /* dQDrvSz = LoWord of size */
- newDrivePtr->dQDrvSz2 = size >> 16; /* dQDrvSz2 = HiWord of size */
-
- AddDrive (drvrRef, *driveNum, (DrvQEl *)&newDrivePtr->qLink);
- }
- else
- result = memFullErr;
- }
- else
- /* more than 32768 drives!?! */
- result = nsDrvErr;
-
- return (result);
- }
-
- /*****************************************************************************/
-
- /*
- ** RemoveDrive
- **
- ** Find the drive queue element for driveNum in the drive queue and Dequeue it.
- ** Return pointer to the drive queue element removed in *drivePtr.
- */
-
- OSErr RemoveDrive (short driveNum, DrvQElPtr *drivePtr)
- {
- QHdrPtr driveQHdr;
-
- driveQHdr = GetDrvQHdr();
- *drivePtr = (DrvQEl *)driveQHdr->qHead; /* get first drive */
- while (*drivePtr && (driveNum != (*drivePtr)->dQDrive)) /* order of tests important! */
- *drivePtr = (DrvQEl *)(*drivePtr)->qLink; /* get next drive */
-
- if (*drivePtr != nil)
- return (Dequeue((QElemPtr)*drivePtr, driveQHdr));
- else
- return (nsDrvErr);
- }
-
- /*****************************************************************************/
- /*****************************************************************************/
-
- #ifdef __DebugVersion
-
- /*****************************************************************************/
-
- short NumToolboxTraps (void)
- {
- if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap) )
- return (0x200);
- else
- return (0x400);
- }
-
- /*****************************************************************************/
-
- TrapType GetTrapType (short theTrap)
- {
- if (theTrap & 0x0800)
- return (ToolTrap);
- else
- return (OSTrap);
- }
-
- /*****************************************************************************/
-
- Boolean TrapAvailable (short theTrap)
- {
- TrapType tType;
-
- tType = GetTrapType(theTrap);
- if (tType == ToolTrap)
- {
- theTrap = theTrap & 0x7FF;
- if (theTrap >= NumToolboxTraps() )
- theTrap = _Unimplemented;
- }
-
- return (NGetTrapAddress(theTrap, tType) !=
- NGetTrapAddress(_Unimplemented, ToolTrap) );
- }
-
- /*****************************************************************************/
-
- #define kMacsbugMacroStr "\p;MC RamDisk 'DM #"
- #define kMacsbugMacroStr2 "\p';g"
-
- #define kTMONMacroStr "\p™AddLabel RamDisk,."
- #define kTMONMacroStr2 "\p,."
-
- #define AddString(src, dst) { BlockMove(&src[1], dst+i, src[0]); i += src[0]; }
-
- /* Add TMON or MacsBug debugger macros for easy viewing of RamDisk */
- void AddDebuggerLabels (DrvrGlobals driverGlobals)
- {
- Str255 strbuf;
- Str31 numstr;
- long tmonVal;
- short err;
- Boolean done = false;
- SignedByte debugFlags;
- short i;
-
- strbuf[0] = 0;
- if (TrapAvailable(_Gestalt)) /* check for TMON */
- {
- err = Gestalt('TMON',&tmonVal);
- if (err == 0)
- {
- /* Add TMON label */
- i = 1;
- AddString(kTMONMacroStr, strbuf);
- NumToString((long)driverGlobals.ramDisk,numstr);
- AddString(numstr, strbuf);
- AddString(kTMONMacroStr2, strbuf);
- NumToString(driverGlobals.ramSize,numstr);
- AddString(numstr, strbuf);
- strbuf[0] = i - 1;
-
- DebugStr(strbuf);
-
- done = true;
- }
- }
- if (!done) /* If TMON isn't installed, define a macro for MacsBug */
- {
- debugFlags = *(SignedByte *) 0x0BFF;
- if (debugFlags == -1)
- debugFlags = *(SignedByte *) 0x0120;
-
- if (debugFlags & 0x20)
- {
- /* Define MacsBug macro */
- i = 1;
-
- AddString(kMacsbugMacroStr, strbuf);
- NumToString((long)driverGlobals.ramDisk, numstr);
- AddString(numstr, strbuf);
- AddString(kMacsbugMacroStr2, strbuf);
- strbuf[0] = i - 1;
-
- DebugStr(strbuf);
- }
- }
- }
-
- /*****************************************************************************/
-
- #endif __DebugVersion
-
- /*****************************************************************************/
-